package edu.scau.ojforwarder.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import edu.scau.ojforwarder.bean.BaseResult;
import org.apache.http.client.fluent.Request;
import org.apache.http.entity.ContentType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CallbackUtil {

    private static Logger logger = LoggerFactory.getLogger(CallbackUtil.class);

    public static void sendResult(String url, BaseResult result) {
        ObjectMapper mapper = new ObjectMapper();
        try {
            Request.Post(url).bodyByteArray(mapper.writeValueAsBytes(result), ContentType.APPLICATION_JSON).execute();
        } catch (Exception e) {
            logger.error("Failed callback to " + url, e);
        }
    }
}
